package com.shopping.mall.core.module.attributeValue.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shopping.mall.base.http.Result;
import com.shopping.mall.core.module.attributeValue.entity.AttributeValue;
import com.shopping.mall.core.module.attributeValue.service.AttributeValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "AttributeValue")
@RestController
@RequestMapping("/attributeValue")
public class AttributeValueController {
    @Autowired
    private AttributeValueService attributeValueService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result<IPage<AttributeValue>> getAttributeValuePage(
        @RequestParam(name = "current", defaultValue = "1") Integer current,
        @RequestParam(name = "size", defaultValue = "10") Integer size,
        AttributeValue attributeValue) {
        IPage<AttributeValue> attributeValuePage=attributeValueService.getAttributeValuePage(current,size,attributeValue);
        return Result.OK(attributeValuePage);
    }

    @ApiOperation("修改")
    @PutMapping
    public Result<AttributeValue> update(@Validated(AttributeValue.update.class) @RequestBody AttributeValue attributeValue) {
        attributeValueService.updateById(attributeValue);
        return Result.OK();
    }

    @ApiOperation("新增")
    @PostMapping
    public Result<Object> add(@Validated(AttributeValue.insert.class) @RequestBody AttributeValue attributeValue) {
        attributeValueService.save(attributeValue);
        return Result.OK();
    }

    @ApiOperation("通过id查询")
    @GetMapping("/id")
    public Result<AttributeValue> getById(@RequestParam String id){
        AttributeValue attributeValue=attributeValueService.getById(id);
        return Result.OK(attributeValue);
    }

    @ApiOperation("查询所有")
    @GetMapping
    public Result<List<AttributeValue>> getAll(AttributeValue attributeValue){
        List<AttributeValue> attributeValueList=attributeValueService.getAll(attributeValue);
        return Result.OK(attributeValueList);
    }

    @ApiOperation("通过id删除")
    @DeleteMapping("/id")
    public Result<Object> deleteById(@RequestParam String id){
        return attributeValueService.deleteById(id);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/batch")
    public Result<Object> batchDelete(@RequestParam List<String> ids){
        return attributeValueService.batchDelete(ids);
    }
}
